/**
 * 
 */
package controller;

import java.util.Hashtable;

import javax.servlet.http.HttpServletRequest;

/**
 * @author alesmana
 *
 */
public abstract class Action {

    // Returns the name of the action, used to match the request in the hash table
    public abstract String getName();

    // Returns the name of the jsp used to render the output.
    public abstract String perform(HttpServletRequest request);

    // Class methods to manage dispatching to Actions
    private static Hashtable<String,Action> hash = new Hashtable<String,Action>();

    public static void add(Action a) {
        hash.put(a.getName(),a);
    }

    public static String perform(String name,HttpServletRequest request) {
        Action a = hash.get(name);
        if (a == null) return null;
        return a.perform(request);
    }
    
    /*
    public boolean isEmpty (String input) {
        if (input == null)
            return false;
        
        if (input.trim().equals(""))
            return false;
        
        return true;
    }
    
    public boolean isUrl(String url) {  
        if(url==null)  {   
            return false;  
        } 
        return url.startsWith("http://"); 
    }

    
    public boolean isEmail(String email) {  
        if(email==null)  {   
            return false;  
        } 
        String emailPattern="^([A-Za-z0-9_\\-\\.])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})";  
        return email.matches(emailPattern);  
    }

    public void getNavigation (UserDAO userDAO, HttpServletRequest request) {
            
        try {
            request.setAttribute("list",userDAO.getUsers());
        } catch (DAOException e) {
            System.out.println("Error: Unable to get navigation");
        }
    }
    */
    
}
